<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>预约API测试</title>
</head>
<body>
    <h1>预约API测试</h1>
    
    <h2>1. 测试预约服务健康状态</h2>
    <button onclick="testHealth()">测试健康状态</button>
    <div id="healthResult"></div>
    
    <h2>2. 测试创建预约</h2>
    <form id="bookingForm">
        <div>
            <label>用户ID:</label>
            <input type="number" id="userId" value="1" required>
        </div>
        <div>
            <label>活动ID:</label>
            <input type="number" id="activityId" value="1" required>
        </div>
        <div>
            <label>预约时间:</label>
            <input type="datetime-local" id="bookingTime" required>
        </div>
        <div>
            <label>备注:</label>
            <textarea id="remark">测试预约</textarea>
        </div>
        <button type="submit">创建预约</button>
    </form>
    <div id="bookingResult"></div>

    <script>
        // 设置默认时间
        document.getElementById('bookingTime').value = new Date().toISOString().slice(0, 16);
        
        async function testHealth() {
            try {
                const response = await fetch('/api/booking/list');
                const result = await response.json();
                document.getElementById('healthResult').innerHTML = 
                    '<pre>' + JSON.stringify(result, null, 2) + '</pre>';
            } catch (error) {
                document.getElementById('healthResult').innerHTML = 
                    '<p style="color: red;">健康检查失败: ' + error.message + '</p>';
            }
        }
        
        document.getElementById('bookingForm').addEventListener('submit', async function(e) {
            e.preventDefault();
            
            // 获取日期时间并格式化为标准格式 "YYYY-MM-DD HH:mm:ss"
            const dateTimeValue = document.getElementById('bookingTime').value;
            const formattedDateTime = dateTimeValue.replace('T', ' ') + ':00';
            
            const bookingData = {
                userId: parseInt(document.getElementById('userId').value),
                activityId: parseInt(document.getElementById('activityId').value),
                bookingTime: formattedDateTime,
                remark: document.getElementById('remark').value
            };
            
            console.log('发送的预约数据:', bookingData);
            
            try {
                const response = await fetch('/api/booking/create', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(bookingData)
                });
                
                const result = await response.json();
                document.getElementById('bookingResult').innerHTML = 
                    '<pre>' + JSON.stringify(result, null, 2) + '</pre>';
            } catch (error) {
                document.getElementById('bookingResult').innerHTML = 
                    '<p style="color: red;">创建预约失败: ' + error.message + '</p>';
            }
        });
    </script>
</body>
</html> 